package com.xingchi.tornado.sms.service.impl;

import com.xingchi.tornado.sms.model.domain.NoteLogRecordDO;
import com.xingchi.tornado.sms.model.dto.NoteLogRecordDTO;
import com.xingchi.tornado.sms.model.dto.NoteLogRecordQueryDTO;
import com.xingchi.tornado.sms.mapper.NoteLogRecordMapper;
import com.xingchi.tornado.sms.service.NoteLogRecordService;
import com.xingchi.tornado.mybatisplus.service.AbstractBasePlusService;
import com.xingchi.tornado.utils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 短信日志记录表 服务实现类
 * </p>
 *
 * @author xingchi
 * @date 2024-05-27 15:33
 */
@Service
public class NoteLogRecordServiceImpl extends AbstractBasePlusService<NoteLogRecordMapper, NoteLogRecordDTO, NoteLogRecordQueryDTO, NoteLogRecordDO> implements NoteLogRecordService {
    @Override
    public Wrapper<NoteLogRecordDO> getWrapper(NoteLogRecordQueryDTO query) {
        return Wrappers.<NoteLogRecordDO>lambdaQuery()
                .eq(StringUtils.isNotBlank(query.getAccount()), NoteLogRecordDO::getAccount, query.getAccount())
                .eq(Objects.nonNull(query.getTemplateId()), NoteLogRecordDO::getTemplateId, query.getTemplateId())
                .eq(Objects.nonNull(query.getMessageId()), NoteLogRecordDO::getMessageId, query.getMessageId());
    }

    /**
     * 批量插入
     *
     * @param records 插入记录
     */
    @Override
    public void saveBatch(List<NoteLogRecordDTO> records) {
        List<NoteLogRecordDO> list = BeanUtils.copyList(records, NoteLogRecordDO.class);
        this.saveBatch(list);
    }
}
